/**
 * 给定N个字符串，对每个字符串Si，求它与其他字符串的最长公共前缀的长度
 * 对所有前缀计数，用哈希。
 * 然后再对每个字符串，倒序前缀，看它的计数器是多少即可
 */
#include <bits/stdc++.h>
using namespace std;

namespace ZIFUCHUAN
{

int const UN = 2;

using hash_t = array<size_t, UN>;
// 10007, 10093
hash_t const Seeds {13313, 10}; // 10用来观察效果
hash_t const ZERO {0, 0};
hash_t const ONE {1, 1};

hash_t const operator + (const hash_t & a, const hash_t & b){
    hash_t ans;
    for(int i=0;i<UN;++i) ans[i] = a[i] + b[i];
    return ans;
}

hash_t const operator - (const hash_t & a, const hash_t & b){
    hash_t ans;
    for(int i=0;i<UN;++i) ans[i] = a[i] - b[i];
    return ans;
}

hash_t const operator * (const hash_t & a, const hash_t & b){
    hash_t ans;
    for(int i=0;i<UN;++i) ans[i] = a[i] * b[i];
    return ans;
}

ostream & operator << (ostream & os, const hash_t & h) {
    os << "[";
    for(int i=0;i<UN;++i){
        os << h[i];
        if(i + 1 == UN) os << "]";
        else os << ",";
    }
    return os;
}

vector<hash_t> Power; // 进制的幂值
void initPower(int n){
    Power.clear();
    Power.reserve(n + 1);
    Power.emplace_back(ONE);

    for(int i=1;i<=n;++i){
        Power.emplace_back(Power.back() * Seeds);
    }

    return;
}

hash_t tr(char c) {
    hash_t ans;
    for(int i=0;i<UN;++i) {
        // ans[i] = c;
        ans[i] = c - 'a' + 1;
    }
    return ans;
}

template<typename IT = string::const_iterator>
struct StrHash
{

/// 
StrHash(IT begin, int n):N(n){
    H.clear();
    H.reserve(N + 1);
    H.emplace_back(ZERO);
    for(int i=1;i<=N;++i){
        H.emplace_back(H.back() * Seeds + tr(*begin++));
    }
    return;
}

/// s[a...b]的哈希, a和b是0-index
hash_t get(int a, int b) const {
    assert(0 <= a and a <= b and b < N);
    // ++a, ++ b;
    // return H[b] - H[a - 1] * Power[b - a + 1];
    return H[b + 1] - H[a] * Power[b - a + 1];
}

vector<hash_t> H;
int N;

};


}

/// 模板偏特化
template<> struct std::hash<ZIFUCHUAN::hash_t> {
    std::size_t operator() (const ZIFUCHUAN::hash_t & p) const {
        std::size_t ret = 0;
        for(auto i : p) ret = ret * 9973 + i;
        return ret;
    }
};

using namespace ZIFUCHUAN;

int N;
string S;

vector<vector<hash_t>> H;
unordered_map<hash_t, int> Map;

void work(){
    initPower(2E6 + 1100);
    
    cin >> N;
    H.assign(N, {});
    for(int i=0;i<N;++i){
        cin >> S;
        int n = S.length();
        StrHash<> h(S.begin(), n);

        for(int j=1;j<=n;++j){
            Map[h.get(0, j - 1)] += 1;
        }

        H[i].swap(h.H);
    }

    for(int i=0;i<N;++i){
        const auto & h = H[i];
        int ans = 0;
        for(int j=h.size()-1;j;--j){
            auto tmp = h[j];
            auto it = Map.find(tmp);
            assert(it != Map.end() and it->second >= 1);
            
            if(it->second > 1){
                ans = j;
                break;
            }
        }
        cout << ans << "\n";
    }
    return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase;
    while(nofkase--) work();
    return 0;
}